﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FangPage.Core;
using FangPage.Common;
using FangPage.Data;
using System.IO;
using ProjectManager.User.Model;

namespace ProjectManager.User.Controller
{
    public class role_list:FPController
    {
        protected string name = FPRequest.GetString("name");

        protected Pager pager = FPRequest.GetModel<Pager>();

        public override void Controller()
        {
            AuthInfo authinfo = Logins.Authorize();

            if (!authinfo.islogin)
            {
                FPResponse.WriteErr("对不起，您尚未登录或登录超时！");
                return;
            }

            if (ispost)
            {
                string ids = FPRequest.GetString("ids");

                DbHelper.ExcuteDelete<RoleInfo>(ids);

                FPResponse.WriteSuccess("删除成功");
            }

            List<SqlParam> where = new List<SqlParam>();

            if (name != "")
            {
                where.Add(DbHelper.MakeAndWhere("name", WhereType.Like, name));
            }

            pager.total = DbHelper.ExcuteCount<RoleInfo>(where.ToArray());

            List<RoleInfo> data = DbHelper.ExcuteList<RoleInfo>(pager.pagesize, pager.pageindex, where.ToArray());

            FPResponse.WriteData(data, pager);
        }
    }
}
